package com.huang.service.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huang.entity.Role;
import com.huang.mapper.RoleDao;
import com.huang.service.RoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author han
 * @since 2021-10-14 11:03:57
 */
@Service
@Transactional
public class RoleServiceImpl extends ServiceImpl<RoleDao, Role> implements RoleService {

    @Resource
    private RoleDao roleDao;

    @Override
    public void saveRoleAndMenu(String id, List<String> menuIds) {
        roleDao.deleteRoleAndMenu(id);
        menuIds.forEach(menuId-> roleDao.saveRoleAndMenu(IdUtil.fastSimpleUUID(), id, menuId));
    }

    @Override
    public List<Role> findByUserId(String userId) {
        return roleDao.findByUserId(userId);
    }
}
